package com.phone;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Created by tisen on 2017/7/4.
 */
public class DBHelper {
    private static SessionFactory factory = null;

    public static void init() {
        Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
        factory = configuration.buildSessionFactory();
    }

    public static Session getSession() {
        if (factory != null)
            return factory.openSession();
        else {
            init();
            return factory.openSession();
        }
    }
}
